<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title th:text="#{title}"></title>
    <link rel="stylesheet" href="/asset/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/asset/css/login.css" media="all"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="login_main">
    <div class="layui-row layui-col-space15">
        <form class="layui-form norml_padding" action="">
            <h2>Panda Admin 旗舰版</h2>
            <div class="layui-col-sm12 layui-col-md12">
                <div class="layui-form-item">
                    <input type="text" name="username" value="admin" lay-verify="required|username" autocomplete="off" placeholder="账号" class="layui-input">
                    <i class="layui-icon layui-icon-username login_icon"></i>
                </div>
            </div>
            <div class="layui-col-sm12 layui-col-md12">
                <div class="layui-form-item">
                    <input type="password" name="password" value="123456" lay-verify="required|password" autocomplete="off" placeholder="密码" class="layui-input">
                    <i class="layui-icon layui-icon-password login_icon"></i>
                </div>
            </div>
            <div class="layui-col-sm12 layui-col-md12">
                <div class="layui-form-item login-captcha-group">
                    <input type="text" name="captcha" value="1234"  lay-verify="required" autocomplete="off" placeholder="验证码 : "  class="layui-input layui-input-captcha"  />
                    <i class="layui-icon layui-icon-vercode  login_icon"></i>
                    <img src="/login/captcha" class="captcha-image" />
                </div>
            </div>
            <div class="layui-col-sm12 layui-col-md12">
                <div class="layui-form-item">
                    <input type="checkbox" name="rememberMe" title="记住密码" lay-skin="primary" checked>
                </div>
            </div>

            <div class="layui-col-sm12 layui-col-md12 norml_margin_20">
                <button class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="login">立即登录</button>
            </div>
        </form>
    </div>
</div>
<div class="panda-copyright">
    <p>copyright © 2017~2021 pandaThink.com all rights reserved.</p>
    <p><a href="http://www.beian.miit.gov.cn/" target="_black">粤ICP备20211113号</a></p>
</div>
</body>
<script type="text/javascript" src="/asset/layui/layui.js"></script>
<script src="/asset/js/common.js"></script>
<script>
    layui.use(['layer', 'form'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;

        $(".captcha-image").on('click',function(){
            $(this).attr('src', '/login/captcha?rand='+Math.random());
        });
		
		$(document).ready(function(){
			if(window != top){
				top.location.href = location.href;
			}
		});

        // 登录事件
        form.on('submit(login)', function (data) {
            $(data.elem).attr('disabled', true).text('登录中....');
            var postParam = data.field;
            if(postParam.rememberMe == 'on'){
                postParam.rememberMe = true;
            }else{
                postParam.rememberMe = false;
            }
            $.ajax({
                type: "POST",
                url: '/login',
                data: postParam,
                success: function (res) {
                    if (res.code == 0) {
                        window.location.href = "/index";
                    } else {
                        if(res.code == 1){
                            console.log(res.msg);
                            layer.msg(res.msg, {icon: 2, anim: 6});
                        }else{ // 重要通知 锁定类 走这里
                            console.log(res.msg);
                            layer.alert(res.msg, {closeBtn: 0});
                        }
                        $('.captcha-image').attr('src', '/login/captcha?rand='+Math.random());
                        $(data.elem).text('登录').removeAttr('disabled');
                    }
                },
                error: function () {
                    $('.captcha-image').attr('src', '/login/captcha?rand='+Math.random());
                    return false;
                }
            });
            return false;
        });
    });
</script>
</html>
